package Thread;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-11
 * Time: 11:34
 */
public class demo37 {
    public static void main(String[] args) throws InterruptedException {
        //参数是可用资源的个数,也就是计数器的初始值
        Semaphore semaphore = new Semaphore(4);
        semaphore.acquire();//申请资源
        System.out.println("申请资源");
        semaphore.acquire();//申请资源
        System.out.println("申请资源");

        semaphore.acquire();//申请资源
        System.out.println("申请资源");

        semaphore.acquire();//申请资源
        System.out.println("申请资源");

        semaphore.release();//释放资源
        System.out.println("释放资源");

        semaphore.acquire();//申请资源
        System.out.println("申请资源");

    }
}
